using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CustomControls
{
    /// <summary>
    /// InterID logic for BPMNExpander.xaml
    /// </summary>

    public partial class BPMNExpander : Expander
    {
        public delegate void ExpanderButtonClick(object sender);
        public event ExpanderButtonClick Click;
        ListBox list = new ListBox();
        
        public BPMNExpander(object header)
        {
            this.Content = list;
            this.Header = header;
            list.SelectionChanged += new SelectionChangedEventHandler(list_SelectionChanged);
            list.GotFocus += new RoutedEventHandler(list_GotFocus);
        }

        void list_GotFocus(object sender, RoutedEventArgs e)
        {
            if (list.SelectedItem != null)
            {
                Tag = (list.SelectedItem as ListBoxItem).Tag;
                Click.Invoke(this);
            }
        }

        void list_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Tag = (list.SelectedItem as ListBoxItem).Tag;
            Click.Invoke(this);
        }

        public void addItem(string text, Image image, object tag)
        {
            ListBoxItem lbi = new ListBoxItem();
            lbi.Tag = tag;
            lbi.Content = text;
            list.Items.Add(lbi);
            if (list.Items.Count == 1)
            {
                Tag = tag;
            }
        }
    }
}